package helloworld.admin.service.teacher;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import helloworld.admin.bean.TeacherAdminBean;
import helloworld.dao.TeacherDao;
import helloworld.dao.DAOException;
import helloworld.dao.DAOFactory;
import helloworld.example.exception.ErrorLevel;

/**
 * TeacherListService provides the Service of Listing Teachers.
 * It is also an example of Session Facade pattern.
 * In real projects, TeacherListService is implemented as Stateful Session EJB.
 * 
 * But this is kept seperate from the TeacherControllerService
 * The reason is that this Service uses ValueListHandler  (Another Core J2EE Pattern) 
 * to access the DAO and is of more stateful nature.
 * Seperating will prevent mingling of this stateful session faceade with 
 * otherwise stateless nature of TeacherControllerService
 * 
 * @author TUYEN-DM
 * @version $Revision:   $ $Date: 2009/05/13  $
 */
public class TeacherListService 
{

	public TeacherAdminBean[] findTeachers(String teacherName) throws TeacherListServiceException
	{
		TeacherAdminBean[] teachers = null;
		try
		{
			DAOFactory daoFactory = DAOFactory.getDAOFactory(DAOFactory.MS_ACCESS);
			TeacherDao dao = daoFactory.getTeacherDAO();
			teachers = dao.find(teacherName);
		}
		catch (DAOException de)
		{
			if (! de.isLogged())
			{
				Log log = LogFactory.getLog("TeacherListService");
				de.log(log);
			}
			throw new TeacherListServiceException(de.getUserMessageKey(), 
									de.getValueReplacementArray(),
									de.getUniqueID(), 
									ErrorLevel.ERROR);
		}
		
		return teachers;
	}

}